<?php

/*
 * Treasure - Reaction
 * 
 * If this is the first time you played a Fool’s Gold this turn, this is worth $1, otherwise it’s worth $4.
 * 
 * When another player gains a Province, you may trash this from your hand. If you do, gain a Gold, putting it on your deck.
 * 
 */

class FoolsGold extends Card implements iKingdom, iHinterlands, iTreasure, iReaction, iReactingCard {

    private $provinceKey;

    public function __construct() {
        parent::__construct("Fools Gold", 2);

        $this->reactConditions = new ReactionConditions();
        $this->reactConditions->action = array(Gain);
        $this->reactConditions->actor = array(SomeoneElse);
        $this->reactConditions->cardLocation = array(PlayHand);
        $this->reactConditions->limit = ForEachCard;

        $province = new Province();
        $this->provinceKey = $province->getKey();
    }

    public function getConditions() {
        return $this->reactConditions;
    }

    public function getDescription() {
        return array(
            "If this is the first time you played a Fool’s Gold this turn, this is worth $1, otherwise it’s worth $4.",
            "When another player gains a Province, you may trash this from your hand. If you do, gain a Gold, putting it on your deck.");
    }

    public function autoPlayNum(Game $game) {
        return 5;
    }

    public function getMoneyValue(Game $game) {
        // is it the first time?
        $playedCards = $game->getPlayedCards();
        $fgplayed = 0;
        $foolsgoldKey = $this->getKey();
        foreach ($playedCards as $card) {
            if ($card->getKey() == $foolsgoldKey) {
                $fgplayed += 1;
            }
        }

        if ($fgplayed == 1) {
            return new Price(1);
        }

        return new Price(4);
    }

    public function isReactRelevant(Game $game, $card, $name) {
        if ($card->getKey() == $this->provinceKey) {
            return true;
        }
        return false;
    }

    public function react(Game $game, $card, $name) {
        if ($card->getKey() == $this->provinceKey) {
            $game->moveCardFromPileToPile($this, PlayHand, Trash, $name);
            $gold = $game->moveCardFromPileToPile("Gold", BoardCards, DrawPile, $name);
            ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($this) . " and put " . nicePrint($gold) . " on top of your deck", "trashes " . nicePrint($this) . " and puts " . nicePrint($gold) . " on top of his deck", $name);
            $game->setTempCard($card);
        }
        return true;
    }

}

?>
